package com.corpgovernment.travelstandard.impl;

import com.corpgovernment.api.travelstandard.service.IMbTravelstandTrainSeatService;
import com.corpgovernment.api.travelstandard.vo.MbTravelstandTrainSeatVo;
import com.corpgovernment.common.base.AbstractBaseService;
import com.corpgovernment.common.base.Page;
import com.corpgovernment.common.utils.ListUtils;
import com.corpgovernment.common.utils.ObjectUtils;
import com.corpgovernment.common.utils.PageUtils;
import com.corpgovernment.travelstandard.entity.db.MbTravelstandTrainSeat;
import com.corpgovernment.travelstandard.mapper.MbTravelstandTrainSeatMapper;
import com.ctrip.corp.obt.shard.context.PageContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MbTravelstandTrainSeatService extends AbstractBaseService implements IMbTravelstandTrainSeatService {

    @Autowired
    private MbTravelstandTrainSeatMapper mbTravelstandTrainSeatMapper;

    @Override
    public void insert(MbTravelstandTrainSeatVo model) {
        mbTravelstandTrainSeatMapper.insertSelective(ObjectUtils.copyProperties(model, MbTravelstandTrainSeat.class));
    }

    @Override
    public int delete(Long id) {
        return mbTravelstandTrainSeatMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(MbTravelstandTrainSeatVo model) {
        return mbTravelstandTrainSeatMapper.updateByPrimaryKeySelective(ObjectUtils.copyProperties(model,MbTravelstandTrainSeat.class));
    }

    @Override
    public MbTravelstandTrainSeatVo get(Long id) {
        return ObjectUtils.copyProperties(mbTravelstandTrainSeatMapper.selectByPrimaryKey(id),MbTravelstandTrainSeatVo.class);
    }

    @Override
    public List<MbTravelstandTrainSeatVo> list(MbTravelstandTrainSeatVo model) {
        return ListUtils.copyList(mbTravelstandTrainSeatMapper.list(ObjectUtils.copyProperties(model,MbTravelstandTrainSeat.class)),MbTravelstandTrainSeatVo.class);
    }

    @Override
    public Page page(MbTravelstandTrainSeatVo model) {
        MbTravelstandTrainSeat param = ObjectUtils.copyProperties(model,MbTravelstandTrainSeat.class);
        PageContext.startPage(model.getPageNum(),model.getPageSize());
        List<MbTravelstandTrainSeat> list = mbTravelstandTrainSeatMapper.list(param);
        return PageUtils.optPageBy(list, MbTravelstandTrainSeatVo.class);
    }

    int deleteByTsId(Long tsId){
        return mbTravelstandTrainSeatMapper.deleteByTsId(tsId);
    }
}
